package com.xiao.mall.message.domain;

import com.xiao.mall.foundation.entity.AbstractAuditingEntity;
import com.xiao.mall.message.domain.converter.MapStringConverter;
import com.xiao.mall.message.domain.enums.NotificationType;
import com.xiao.mall.message.domain.enums.NotificationTopic;
import com.xiao.mall.message.domain.enums.TargetType;
import lombok.*;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import static javax.persistence.GenerationType.IDENTITY;

@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "t_notification")
@EqualsAndHashCode(callSuper = false)
@SuperBuilder
@Getter
@Setter
public class Notification extends AbstractAuditingEntity implements Serializable {

    private static final long serialVersionUID = -7249288039237232899L;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;

    @Column(length = 40)
    private String title;

    @Column(length = 1000)
    private String content;

    @Enumerated(value = EnumType.STRING)
    private NotificationType type;

    @Column(length = 60)
    @Enumerated(value = EnumType.STRING)
    private NotificationTopic topic; //消息主题

    @Column(length = 20)
    private String target; //目标id

    @Column(length = 120)
    @Enumerated(value = EnumType.STRING)
    private TargetType targetType; //目标类型

    @Column(length = 60)
    private String action; //提醒信息的动作类型

    @Column(length = 60)
    private String sender; //发送人

    @OneToMany(cascade = {CascadeType.REMOVE}, mappedBy = "notification",
            fetch = FetchType.LAZY, orphanRemoval = true)
    private List<UserNotification> userNotifications;

    @Column(length = 128)
    private String templateId;

    @Column(length = 256)
    private String wechatPageUrl;

    @Column(columnDefinition = "TEXT")
    @Convert(converter = MapStringConverter.class)
    private Map<String, Object> wechatTemplateArgs;
}
